package com.example.constellation.Fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

import com.example.constellation.Activity.fg3ysActivity;
import com.example.constellation.Adapter.fg3guideradapter;
import com.example.constellation.R;
import com.example.constellation.bean.StarBean;

import java.io.Serializable;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class Fragment3 extends Fragment {
    private GridView fg3gv;
    private List<StarBean.StarinfoBean> mdata;
    private fg3guideradapter fg3guideradapter;


    @Override
    public View onCreateView(final LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view= inflater.inflate(R.layout.fragment_3, container, false);
        fg3gv=view.findViewById(R.id.fg3gv);
        //获取数据源
        Bundle bundle = getArguments();
        StarBean infobean = (StarBean) bundle.getSerializable("info");
        mdata=infobean.getStarinfo();
        //设置适配器
        fg3guideradapter = new fg3guideradapter(getContext(), mdata);
        fg3gv.setAdapter(fg3guideradapter);
        //设置guideview的监听事件
        fg3gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                StarBean.StarinfoBean Bean = mdata.get(position);
                String name = Bean.getName();
                Intent intent = new Intent(getContext(), fg3ysActivity.class);
                intent.putExtra("name",name);
                startActivity(intent);

            }
        });
        return view;
    }
}
